/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package picturemouse;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Duncan
 */
public class AdminHome extends javax.swing.JFrame {

    private PictureMouse server;
    
    /**
     * Creates new form AdminHome
     */
    public AdminHome(PictureMouse server) {
        this.server = server;
        initComponents();
        setVisible(true);
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        changeFilmsButton = new javax.swing.JButton();
        changeReviewsButton = new javax.swing.JButton();
        distributeNewsletterButton = new javax.swing.JButton();
        changeAccountsButton = new javax.swing.JButton();
        shutdownLabel = new javax.swing.JLabel();
        shutdownButton = new javax.swing.JButton();
        logoutButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 30)); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("PictureMouse Admin Panel");

        changeFilmsButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        changeFilmsButton.setText("Change Films");
        changeFilmsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeFilmsButtonActionPerformed(evt);
            }
        });

        changeReviewsButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        changeReviewsButton.setText("Change Reviews");
        changeReviewsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeReviewsButtonActionPerformed(evt);
            }
        });

        distributeNewsletterButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        distributeNewsletterButton.setText("Distribute Newsletter");
        distributeNewsletterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                distributeNewsletterButtonActionPerformed(evt);
            }
        });

        changeAccountsButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        changeAccountsButton.setText("Change Accounts");
        changeAccountsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeAccountsButtonActionPerformed(evt);
            }
        });

        shutdownLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        shutdownLabel.setText("Shutdown PictureMouse:");

        shutdownButton.setText("Shutdown");
        shutdownButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shutdownButtonActionPerformed(evt);
            }
        });

        logoutButton.setText("Logout");
        logoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addGap(166, 166, 166))
            .addGroup(layout.createSequentialGroup()
                .addGap(129, 129, 129)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(logoutButton)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(changeFilmsButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(changeAccountsButton, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)))
                .addGap(41, 41, 41)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(changeReviewsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(distributeNewsletterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(shutdownLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(shutdownButton)))
                .addContainerGap(130, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(changeFilmsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(changeReviewsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(changeAccountsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(distributeNewsletterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(shutdownButton)
                    .addComponent(shutdownLabel)
                    .addComponent(logoutButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void changeFilmsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeFilmsButtonActionPerformed
        new ChangeFilms(server);
        this.dispose();
    }//GEN-LAST:event_changeFilmsButtonActionPerformed

    private void changeReviewsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeReviewsButtonActionPerformed
        new ChangeReviews(server);
        this.dispose();
    }//GEN-LAST:event_changeReviewsButtonActionPerformed

    private void distributeNewsletterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_distributeNewsletterButtonActionPerformed
        new DistributeNewsletter(server);
        this.dispose();
    }//GEN-LAST:event_distributeNewsletterButtonActionPerformed

    private void changeAccountsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeAccountsButtonActionPerformed
        new ChangeAccounts(server);
        this.dispose();
    }//GEN-LAST:event_changeAccountsButtonActionPerformed

    private void shutdownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shutdownButtonActionPerformed
        //Save the data
        try {
            server.saveData("PictureMouseData");
        } catch (FileNotFoundException e) {
            JOptionPane.showMessageDialog(null, "File not found.");
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, "General I/O error.");
        }
        
        System.exit(0);
        
    }//GEN-LAST:event_shutdownButtonActionPerformed

    private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutButtonActionPerformed
        new Login(server);
        this.dispose();
        server.currentAccount = null;
    }//GEN-LAST:event_logoutButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton changeAccountsButton;
    private javax.swing.JButton changeFilmsButton;
    private javax.swing.JButton changeReviewsButton;
    private javax.swing.JButton distributeNewsletterButton;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JButton logoutButton;
    private javax.swing.JButton shutdownButton;
    private javax.swing.JLabel shutdownLabel;
    // End of variables declaration//GEN-END:variables
}
